package 扫雷;

import java.util.Scanner;

public class Main {
    static int N = 310, n;
    static char[][] str = new char[N][N];
    static int[][] g = new int[N][N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
        for (int cases = 1; cases <= T; cases++) {
            n = in.nextInt();
            for (int i = 0; i < n; i++) {
                str[i] = in.next().toCharArray();
            }
//            for (int i = 0; i < n; i++) {
//                for (int j = 0; j < n; j++) {
//                    System.out.print(str[i][j]);
//                }
//                System.out.println();
//            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (str[i][j] == '*') {
                        g[i][j] = -1;
                    } else {
                        g[i][j] = 0;
                        for (int x = i - 1; x <= i + 1; x++) {
                            for (int y = j - 1; y <= j + 1; y++) {
                                if (x >= 0 && x < n && y >= 0 && y < n && str[x][y] == '*') {
                                    g[i][j]++;
                                }
                            }
                        }
                    }
                }
            }
            int res = 0;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (g[i][j] == 0) {
                        res++;
                        dfs(i, j);
                    }
                }
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (g[i][j] != -1) {
                        res++;
                    }
                }
            }
            System.out.printf("Case #%d: %d\n", cases, res);
        }
    }

    private static void dfs(int a, int b) {
        int t = g[a][b];
        g[a][b] = -1;
        if (t != 0) {
            return;
        }
        for (int i = a - 1; i <= a + 1; i++) {
            for (int j = b - 1; j <= b + 1; j++) {
                if (i >= 0 && i < n && j >= 0 && j < n && g[i][j] != -1) {
                    dfs(i, j);
                }
            }
        }
    }
}
